package com.bzkj.msfx.service.impl;


import com.bzkj.common.core.domain.AjaxResult;
import com.bzkj.msfx.domain.CustomerMap;
import com.bzkj.msfx.mapper.CustomerMapMapper;
import com.bzkj.msfx.service.CustomerMapService;
import com.bzkj.msfx.utils.FusionHttpUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * @projectName: btyy
 * @package: com.bzkj.btyy.service.impl
 * @className: CustomerMapServiceImpl
 * @description: 往来单位映射服务层
 * @author: C1309
 * @createDate: 2024年03月22日
 * @version: v1.0
 */
@Service
public class CustomerMapServiceImpl implements CustomerMapService {
    @Resource
    private FusionHttpUtils fusionHttpUtils;

    @Resource
    private CustomerMapMapper customerMapMapper;

    /**
     * 查询映射信息列表
     *
     * @param customerMap 查询名字条件
     * @return 查询结果
     */
    @Override
    public ArrayList<CustomerMap> queryErpCustomer(CustomerMap customerMap) {
        return customerMapMapper.queryErpCustomer(customerMap);
    }


    /**
     * 更新ERP往来单位信息
     *
     * @param customerMap 更新信息
     * @return 更新结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult updateCustomerMap(CustomerMap customerMap) {
        try {
            AjaxResult ajaxResult = fusionHttpUtils.sendPut("/customerMap", customerMap);
            if (ajaxResult.isSuccess()){
                customerMapMapper.updateMap(customerMap);
            }
            return ajaxResult;
        } catch (Exception e) {
            throw  new RuntimeException("往来单位映射信息更新失败，原因：" + e.getMessage());
        }
    }
}
